<?php
   function send_load_lab(){
      if(isset($_SESSION['logged_in']) && $_SESSION['permissions'] == "Student")
      return true;
   else
      return false;
   }
   function send_menu_lab(){
     return "<br><a href=?q=lab>Lab Reg</a><br>";
   }
   function send_content_lab(){
      if(!isset($_GET['q']))return;
      if($_GET['q']=="lab")
      {

         $query = "select * from lab_details";
         $result = query_db($query);

         $faculty = "<select name='Faculty'>";
         while($row = mysql_fetch_array($result, MYSQL_NUM))
         {
            $faculty .= "<option value='$row[0],$row[1]'>$row[0], $row[1]</option>";
         }
         $faculty .= "</select><br>";

	$content ='<script language="JavaScript" src="include/calendar/jquery-1.3.2.min.js"></script>
                        <script language="JavaScript" src="include/calendar/cal.js"></script>
                        <script language="JavaScript" src="include/calendar/cal2.js"></script>
                    <form name="contactform" method="post" action="?q=lab_submit">
	               <table width="450px">
	               </tr>
	               <tr>
	               </tr>
				        <tr>
                          <td valign="top">
                             <label for="enrollment no.">Enrollment No. *</label>
                          </td>
                          <td valign="top">
                             <input type="text"  type="text" name="enrollment_no" maxlength="80" size="30">
                          </td>
                       </tr>
					     <tr>
                          <td valign="top">
                             <label for="used_by">Used_by *</label>
                          </td>
                          <td valign="top">
                             <input type="text"  type="text" name="used_by" maxlength="80" size="30">
                          </td>
                       </tr>

	               <tr>
                          <td valign="top"">
                             <label for="faculty_incharge">Faculty Incharge & Lab Name *</label>
                          </td>
                          <td valign="top">';
           $content .= $faculty;
           $content .= '
                          </td>
                       </tr>
                       <tr>
                          <td valign="top">
                             <label for="day_of_usage">Day of Usage *</label>
                          </td>
                          <td valign="top">
                             <input class="one"  type="text" name="day_of_usage" maxlength="80" size="30">
                          </td>
                       </tr>
                       
                       <tr>
                          <td valign="top">
                             <label for="time_of_usage">Time of Usage (in Hours)*</label>
                          </td>
                          <td valign="top">
                             <input type="text"  name="time_of_usage" maxlength="80" size=30></textarea>
                          </td>
                       </tr>
						<tr>
                          <td valign="top">
                             <label for="comments">Comments *</label>
                          </td>
                          <td valign="top">
                             <textarea  name="comments" maxlength="1000" cols="25" rows="6"></textarea>
                          </td>
                       </tr>
                       <tr>
                          <td colspan="2" style="text-align:center">
                             <input type="submit" value="Submit"> 
                          </td>
                       </tr>
                       </table>
                    </form>';
					return $content;    
      }
      else if($_GET['q'] == "lab_submit")
     
      {
         global $db_agent;

         if($db_agent == "mysql")
         {
            
            $lab_name = $_POST['Faculty'];
            $temp = preg_split("/,/",$lab_name,-1,PREG_SPLIT_OFFSET_CAPTURE);
            $faculty_incharge  = $_POST['Faculty'];
            $lab_name = $temp[0][0];
            $faculty_incharge = $temp[1][0];
            $uid=$_POST['enrollment_no'];
			$used_by=$_POST['used_by'];
            $day_of_usage= $_POST['day_of_usage'];
            if($day_of_usage == "")
            return "Day_of_Usage is mandatory";

            $d_o_b = preg_split("/\//",$day_of_usage,-1,PREG_SPLIT_OFFSET_CAPTURE);
            $date = $d_o_b[1][0];
            $month = $d_o_b[0][0];
            $year = $d_o_b[2][0];

            $time_of_usage = $_POST['time_of_usage'];
			$Comments = $_POST['comments'];
                

            $query = "insert into lab values('$used_by','$lab_name','$uid','$faculty_incharge', '$year-$month-$date','$time_of_usage','$Comments', @)";
            $result = query_db($query);
            if(!$result)
               return "Problem with SQL";

            return "Lab usage recorded successfuly";
         }
         
      }
   }
   function send_content_other_lab()
   {
   
      
   }
  
?>
